define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $(".btn-edit").data("area",["100%","100%"]);
            $(".btn-add").data("area",["100%","100%"]);
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods/brand/index' + location.search,
                    add_url: 'goods/brand/add',
                    edit_url: 'goods/brand/edit',
                    del_url: 'goods/brand/del',
                    multi_url: 'goods/brand/multi',
                    import_url: 'goods/brand/import',
                    table: 'brand',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'name', title: __('Name'), operate: false},
                        {field: 'first', title: __('First'), operate: false,visible: false},
                        {
                            field: 'logoimage',
                            title: __('Logoimage'),
                            operate: false,
                            events: Table.api.events.image,
                            formatter: function(value,row,index,custom){
                                var classname = typeof custom !== 'undefined' ? custom : 'img-lg img-center';

                                return '<a href="javascript:;">' +
                                    '<img class="' + classname + '" src="' + Fast.api.cdnurl(value) + '" />' +
                                    '</a>';

                            }
                        },
                        {field: 'brandurl', title: __('Brandurl'), operate: false, formatter: Table.api.formatter.url},
                        {field: 'status', title: __('Status'),operate: false, searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'weigh', title: __('Weigh'), operate: false, visible: false},
                        {field: 'create_time', title: __('Create_time'), operate: false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,

                        }
                    ]
                ]
            });
            table.on('post-body.bs.table',function(){
                $(".btn-editone").data("area",["100%","100%"]);
            })
            $('.panel-heading a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var field = $(this).closest("ul").data("field");
                var value = $(this).data("value");
                var options = table.bootstrapTable('getOptions');
                console.log(field)
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    var filter = {};
                    if (value !== '') {
                        filter[field] = value;
                    }
                    params.filter = JSON.stringify(filter);
                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
